/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session.TX;

import entity.Outlet;
import entity.OutletReservation;
import entity.StakeholderFood;
import entity.Users;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Chen Zhe
 */
@Stateless
@LocalBean
public class PopulateTTAneededDataSB implements PopulateTTAneededDataSBRemote {

    @PersistenceContext()
    EntityManager em;

    @Override
    public void populate() {

        //create Jacob@gmail.com
        Users customer1 = new Users();
        customer1.setId(new Long(1));
        customer1.setCountry("P R China");
        Calendar birthDay = Calendar.getInstance();
        birthDay.set(Calendar.YEAR, 1983);
        customer1.setBirthDate(birthDay.getTime());
        customer1.setEmail("Jacob@gmail.com");
        em.persist(customer1);
        em.flush();

        //create Randall@gmail.com
        Users customer2 = new Users();
        customer2.setId(new Long(2));
        customer2.setCountry("Hong Kong SAR");
        Calendar birthDay2 = Calendar.getInstance();
        birthDay2.set(Calendar.YEAR, 1976);
        customer2.setBirthDate(birthDay2.getTime());
        customer2.setEmail("Randall@gmail.com");
        em.persist(customer2);
        em.flush();

        //create Weida@gamil.com
        Users customer3 = new Users();
        customer3.setId(new Long(3));
        customer3.setCountry("Other Countries in Southeast Asia");
        Calendar birthDay3 = Calendar.getInstance();
        birthDay3.set(Calendar.YEAR, 1966);
        customer3.setBirthDate(birthDay3.getTime());
        customer3.setEmail("Weida@gmail.com");
        em.persist(customer3);
        em.flush();

        //create Mingzhou@gmail.com
        Users customer4 = new Users();
        customer4.setId(new Long(4));
        customer4.setCountry("India");
        Calendar birthDay4 = Calendar.getInstance();
        birthDay4.set(Calendar.YEAR, 1956);
        customer4.setBirthDate(birthDay4.getTime());
        customer4.setEmail("Mingzhou@gmail.com");
        em.persist(customer4);
        em.flush();

        //create Stewart@gmail.com
        Users customer5 = new Users();
        customer5.setId(new Long(5));
        customer5.setCountry("Thailand");
        Calendar birthDay5 = Calendar.getInstance();
        birthDay5.set(Calendar.YEAR, 1946);
        customer5.setBirthDate(birthDay5.getTime());
        customer5.setEmail("Steart@gmail.com");
        em.persist(customer5);
        em.flush();

        //create Fenglong@gmail.com
        Users customer6 = new Users();
        customer6.setId(new Long(6));
        customer6.setCountry("Japan");
        Calendar birthDay6 = Calendar.getInstance();
        birthDay6.set(Calendar.YEAR, 1996);
        customer6.setBirthDate(birthDay6.getTime());
        customer6.setEmail("Fenglong@gmail.com");
        em.persist(customer6);
        em.flush();

        //creat outlet with outlet id 1 2 3 4

        Outlet o1 = new Outlet();
        o1.setId(new Long(1));
        em.persist(o1);
        em.flush();

        Outlet o2 = new Outlet();
        o2.setId(new Long(2));
        em.persist(o2);
        em.flush();

        Outlet o3 = new Outlet();
        o3.setId(new Long(3));
        em.persist(o3);
        em.flush();

        Outlet o4 = new Outlet();
        o4.setId(new Long(4));
        em.persist(o4);
        em.flush();
        
        StakeholderFood s1 = new StakeholderFood();
        s1.setName("Mcdonald");
        List<Outlet> outlets = new ArrayList<Outlet>();
        outlets.add(o1);
        outlets.add(o2);
        s1.setOutlet(outlets);
        s1.setEmail("mcdonald@gmail.com");
        s1.setPurchaseBI(true);
        em.persist(s1);
        em.flush();
        
        StakeholderFood s2 = new StakeholderFood();
        s2.setName("KFC");
        List<Outlet> outlets2 = new ArrayList<Outlet>();
        outlets2.add(o3);
        outlets2.add(o4);
        s2.setOutlet(outlets);
        s2.setEmail("KFC@gmail.com");
        s2.setPurchaseBI(true);
        em.persist(s2);
        em.flush();
        
        StakeholderFood sf1 = em.find(StakeholderFood.class,"Mcdonald");
        StakeholderFood sf2 = em.find(StakeholderFood.class,"KFC");
        
        Outlet outlet1 =em.find(Outlet.class, new Long(1));
        outlet1.setStakeholder(sf1);
        Outlet outlet2 =em.find(Outlet.class, new Long(2));
        outlet2.setStakeholder(sf1);
        Outlet outlet3 =em.find(Outlet.class, new Long(3));
        outlet3.setStakeholder(sf2);
        Outlet outlet4 =em.find(Outlet.class, new Long(4));
        outlet4.setStakeholder(sf2);
        em.persist(outlet1);
        em.persist(outlet2);
        em.persist(outlet3);
        em.persist(outlet4);
        em.flush();
        
        Calendar timeslot = Calendar.getInstance();

        //create outletReservations
        // Jacob books outletid:1 on 2011/04/04
        OutletReservation or1 = new OutletReservation();
        or1.setCustomer(customer1);
        or1.setOutlet(o1);
        timeslot.set(2011, 3, 4);
        or1.setTimeslot(timeslot);
        or1.setConfirmStatus(true);
        or1.setCustomerShowUp(true);
        or1.setId(new Long(1));
        em.persist(or1);
        em.flush();
        
        // Jacob books outletid:1 on 2011/04/04
        OutletReservation or2 = new OutletReservation();
        or2.setCustomer(customer1);
        or2.setOutlet(o1);
        timeslot.set(2011, 3, 4);
        or2.setTimeslot(timeslot);
        or2.setConfirmStatus(true);
        or2.setCustomerShowUp(true);
        or2.setId(new Long(2));
        em.persist(or2);
        em.flush();

        // Jacob books outletid:1 on 2011/05/04
        OutletReservation or3 = new OutletReservation();
        or3.setCustomer(customer1);
        or3.setOutlet(o1);
        timeslot.set(2011, 4, 4);
        or3.setTimeslot(timeslot);
        or3.setConfirmStatus(true);
        or3.setCustomerShowUp(true);
        or3.setId(new Long(3));
        em.persist(or3);
        em.flush();
        // Jacob books outletid:1 on 2011/04/04, but never show up
        OutletReservation or4 = new OutletReservation();
        or4.setCustomer(customer1);
        or4.setOutlet(o1);
        timeslot.set(2011, 4, 4);
        or4.setTimeslot(timeslot);
        or4.setConfirmStatus(true);
        or4.setCustomerShowUp(false);
        or4.setId(new Long(4));
        em.persist(or4);
        em.flush();

        // Mingzhou books outletid:2 on 2011/07/04
        OutletReservation or5 = new OutletReservation();
        or5.setCustomer(customer4);
        or5.setOutlet(o2);
        timeslot.set(2011, 6, 4);
        or5.setTimeslot(timeslot);
        or5.setConfirmStatus(true);
        or5.setCustomerShowUp(true);
        or5.setId(new Long(5));
        em.persist(or5);
        em.flush();

        // Mingzhou books outletid:3 on 2011/05/04
        OutletReservation or6 = new OutletReservation();
        or6.setCustomer(customer4);
        or6.setOutlet(o3);
        timeslot.set(2011, 4, 4);
        or6.setTimeslot(timeslot);
        or6.setConfirmStatus(true);
        or6.setCustomerShowUp(true);
        or6.setId(new Long(6));
        em.persist(or6);
        em.flush();

        // Jacob books outletid:1 on 2011/04/04
        OutletReservation or7 = new OutletReservation();
        or7.setCustomer(customer1);
        or7.setOutlet(o1);
        timeslot.set(2011, 10, 4);
        or7.setTimeslot(timeslot);
        or7.setConfirmStatus(true);
        or7.setCustomerShowUp(true);
        or7.setId(new Long(7));
        em.persist(or7);
        em.flush();
    }
    
 
}
